<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>任务查看</title>
    <link rel="stylesheet" type="text/css" href="../../easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../easyui/themes/icon.css">
    <script type="text/javascript" src="../../easyui/jquery.min.js"></script>
    <script type="text/javascript" src="../../easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" th:inline="none">

        $(function () {
            $('#taskDataGrid').datagrid({
                rownumbers:true,//显示行号
                pagination:true,//在dataGrid组件的底部显示分页工具栏效果
                pageSize:2,//设置每页显示两条数据
                pageList:[2,4,6],//设置分页组件中每页显示的数据量的下拉框中的数据
                title:'查询结果',
                toolbar:'#tb',//设置DataGrid组建的工具栏效果
                autoRowHeight:false,
                url:"task/taskInfo",//主持人信息加载的后台url地址

                columns:[[
                    {field:'aa',title:'aa',checkbox:true},
                    {field:'taskId',title:'任务编号',width:250,align:'center',hidden:true},
                    {field:'taskName',title:'标题',width:250,align:'center'},
                    {field:'endTime',title:'截至时间',width:250,align:'center'},
                    {field:'userName',title:'执行人员',width:250,align:'center',formatter:
                        function (value,rows,index) {
                            return rows.user.userName;
                        }
                    },
                    {field:'taskStatus',title:'状态',width:250,align:'center',formatter:
                        function (value, rows, index) {
                            if (value==0){
                                return "完成";
                            }else if (value==1) {
                                return "未完成";
                            }else {
                                return "放弃完成"
                            }
                        }
                    },
                    {field:'taskIsUrgent',title:'紧急程度',width:250,align:'center',formatter:
                            function (value, rows, index) {
                                if (value==0){
                                    return "紧急";
                                }else {
                                    return "不紧急";
                                }
                            }
                    }
                ]]
            });
        });

        function selectBtn() {
            var taskName=$("#taskName").val();

            $("#taskDataGrid").datagrid('load',{
                taskName:taskName
            })
        }

    //给任务完成绑定一个单击事件
        $(function () {
            //获取按钮对象
            $("#missionAccomplished").click(function () {
                var line=$("#taskDataGrid").datagrid('getChecked');
                if (line.length>1){
                    $.messager.alert("提示","一次只能提交一次任务","info");
                }else if (line.length==1) {
                    var checked=$("#taskDataGrid").datagrid('getChecked');
                    var data=checked[0].taskId;
                    console.log(data)
                    $.ajax({
                        url: "endTask",
                        data:{taskId:data},
                        success:function (data) {
                            if (data=1){
                                $("#taskDataGrid").datagrid('load')
                            }
                        }

                    })


                }else {
                    $.messager.alert("提示","请选择你要提交的任务","info");
                }
            })

        })

        //给任务完成绑定一个单击事件
        $(function () {
            //获取按钮对象
            $("#passTask").click(function () {
                var line=$("#taskDataGrid").datagrid('getChecked');
                if (line.length>1){
                    $.messager.alert("提示","一次只能提交一次任务","info");
                }else if (line.length==1) {
                    var checked=$("#taskDataGrid").datagrid('getChecked');
                    var data=checked[0].taskId;
                    console.log(data)
                    $.ajax({
                        url: "task/passTask",
                        data:{taskId:data},
                        success:function (data) {
                            if (data=1){
                                $("#taskDataGrid").datagrid('load')
                            }
                        }

                    })


                }else {
                    $.messager.alert("提示","请选择你要提交的任务","info");
                }
            })

        })

        //给任务完成绑定一个单击事件
        $(function () {
            //获取按钮对象
            $("#postponeTask").click(function () {
                var line=$("#taskDataGrid").datagrid('getChecked');
                if (line.length>1){
                    $.messager.alert("提示","一次只能提交一次任务","info");
                }else if (line.length==1) {


                    $("#postponeDialog").dialog('open');

                }else {
                    $.messager.alert("提示","请选择你要提交的任务","info");
                }
            })

        })

        //给任务完成绑定一个单击事件
        $(function () {
            //获取按钮对象
            $("#transferTask").click(function () {
                var line=$("#taskDataGrid").datagrid('getChecked');
                if (line.length>1){
                    $.messager.alert("提示","一次只能提交一次任务","info");
                }else if (line.length==1) {


                    $("#transferDialog").dialog('open');

                }else {
                    $.messager.alert("提示","请选择你要提交的任务","info");
                }
            })

        })

    //    给提交申请绑定一个单击事件
        $(function () {
            $("#submitBtn").click(function () {

                var checked=$("#taskDataGrid").datagrid('getChecked');
                var taskId=checked[0].taskId;
                var implementId=checked[0].implementId;
                var postponeTime=$("#postponeTime").val();
                var postponeDesc=$("#postponeDesc").val();
                $.ajax({
                    url: "postpone/postponeInfo",
                    data:{taskId:taskId,implementId:implementId,postponeTime:postponeTime,postponeDesc:postponeDesc},
                    success:function (data) {
                        if (data=1){
                            $.messager.alert("提示","申请成功，等待审核","info")
                            $("#postponeDialog").dialog('close');
                        }
                    }

                })


            })
        })

        //    给提交申请绑定一个单击事件
        $(function () {
            $("#submitBtnTransfer").click(function () {

                var checked=$("#taskDataGrid").datagrid('getChecked');
                var taskId=checked[0].taskId;
                var implementId=checked[0].implementId;
                var transferDesc=$("#transferDesc").val();
                $.ajax({
                    url: "transfer/transferInfo",
                    data:{taskId:taskId,implementId:implementId,transferDesc:transferDesc},
                    success:function (data) {
                        if (data=1){
                            $.messager.alert("提示","申请成功，等待审核","info")
                            $("#transferDialog").dialog('close');
                        }
                    }

                })


            })
        })

    </script>
</head>



<body>

<!--申明panel面板-->
<div id="p" class="easyui-panel" title=""
     style="width:500px;height:150px;padding:10px;background:#fafafa;"
     data-options="fit:true">

    <!--头部查询条件-->
    <div style="margin-bottom:20px;margin-left: 200px;margin-top: 30px">
        <input class="easyui-textbox" name="taskName" id="taskName" style="width:300px" data-options="label:'任务标题:',required:true">
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="selectBtn()" style="width:80px">查询</a>
    </div>

    <!--使用DataGrid组件完成页面的-->
    <div style="width: 80%;margin: auto;margin-top: 50px">
        <table id="taskDataGrid"></table>
    </div>

    <div id="tb">
        <a id="missionAccomplished" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">任务完成</a>
        <a id="passTask" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">任务放弃</a>
        <a id="postponeTask" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">任务延期</a>
        <a id="transferTask" href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">任务转移</a>

    </div>

</div>

<div id="postponeDialog" class="easyui-dialog" title="延期申请" style="width:500px;height:300px;padding:10px;text-align: center"
     data-options="iconCls:'icon-save',resizable:true,modal:true,buttons:'#submitApplications',closed:true">

    <div style="margin-bottom:20px">
        <input class="easyui-datebox" id="postponeTime" label="延期时间:" data-options="formatter:myformatter,parser:myparser" style="width:70%;">
    </div>

    <div style="margin-bottom:20px">
        <input class="easyui-textbox" id="postponeDesc" label="申请原因:" labelPosition="top" multiline="true" style="width:100%;height:120px">
    </div>

</div>

<div id="submitApplications">
    <a href="javascript:void(0)" id="submitBtn" class="easyui-linkbutton">提交申请</a>
</div>

<script type="text/javascript">
    function myformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
    }
    function myparser(s){
        if (!s) return new Date();
        var ss = (s.split('-'));
        var y = parseInt(ss[0],10);
        var m = parseInt(ss[1],10);
        var d = parseInt(ss[2],10);
        if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
            return new Date(y,m-1,d);
        } else {
            return new Date();
        }
    }
</script>

<div id="transferDialog" class="easyui-dialog" title="转移申请" style="width:500px;height:300px;padding:10px;text-align: center"
     data-options="iconCls:'icon-save',resizable:true,modal:true,buttons:'#submitApplicationsTransfer',closed:true">

    <div style="margin-bottom:20px">
        <input class="easyui-textbox" id="transferDesc" label="申请原因:" labelPosition="top" multiline="true" style="width:100%;height:120px">
    </div>

</div>

<div id="submitApplicationsTransfer">
    <a href="javascript:void(0)" id="submitBtnTransfer" class="easyui-linkbutton">提交申请</a>
</div>

</body>
</html>